<style type="text/css">
	legend {
		font-size:8px;
		font-weight:bold;
		text-transform:uppercase;
		background:#f1f1f1;
		border-top:1px dotted #333;
		border-left:1px dotted #333;
		border-right:1px dotted #333;
		padding:3px;
		background:#ddd;
	}
	fieldset {
		background:#f4f4f4;
		border:1px dotted #333;
                margin-top: 10px;
	}
	.noborder {
		border:none;
		background:none;
	}
	input[type=button] {
		font-size:11px;
	}
</style>
<script type="text/javascript">
    $(document).ready(function(){
        $('.add-form').hide();
        $('.add').click(function(){
            $('.add-form').slideToggle('fast');
        })
        
        $('#sekolah').autocomplete("<?php echo site_url('ajax_target');?>",
        {
            parse: function(data){
                var parsed = [];
                for (var i=0; i < data.length; i++) {
                    parsed[i] = {
                        data: data[i],
                        value: data[i].nama // nama field yang dicari
                    };
                }
                return parsed;
            },
            formatItem: function(data,i,max){
                var str='<div class=result>'+data.nama+'<br />Alamat: '+data.alamat+'</div>';
                return str;
            },
            width: 270, // panjang tampilan pencarian autocomplete yang akan muncul di bawah textbox pencarian
            dataType: 'json' // tipe data yang diterima oleh library ini disetup sebagai JSON
        }).result(
            function(event,data,formated){
                $(this).attr('value',data.nama);
                $('#idSekolah').val(data.id);
                $.ajax({
                   url: "<?php echo site_url('ajax_target/selectKelas');?>"+"/"+data.id_tingkat_pendidikan,
                   cache: false,
                   type: 'POST',
                   dataType: 'json',
                   success: function(msg){
                       var str = "<option value=''>Pilih kelas</option>";
                       for(var i=0;i<msg.length;i++){
                           str += "<option value='"+msg[i].id+"'>"+msg[i].nama+" "+msg[i].tingkat_pendidikan+"</option>";
                       }
                       $('#kelas').html(str);
                   }
                });
            }
        );
            
        $("input[type=submit]").click(function(){
            if($('#alamat').val() == ""){
                alert('Alamat tidak boleh kosong');
                $('#alamat').focus();
                return false;
            }
            if($('#sekolah').val() == ""){
                alert('Sekolah tidak boleh kosong');
                $('#sekolah').focus();
                return false;
            }
            if($('#idSekolah').val() == ""){
                alert('Pilih sekolah dengan benar');
                $('#sekolah').focus();
                return false;
            }
            if($('#kelas').val() == ""){
                alert('Kelas harus dipilih');
                $('#kelas').focus();
                return false;
            }
        })    
    })
</script>
<script type="text/javascript">
    $(document).ready(function(){
        $("img[rel]").overlay();        
    })  
</script>
<div class="judul"><?php echo anchor($linkBack, $title);?> <span class="breadcrumb"><?php echo "$titlePage";?></span></div>
<?php
  $flashdata = $this->session->flashdata('message');
  $messages = isset ($flashdata)?pesan($flashdata):"";
  echo "$messages";
?>
<fieldset>
    <legend><?php echo "$titlePage";?></legend>
    <?php
      foreach ($listCalonAdikAsuh as $row);
    ?>
    <div style="width: 500px;float: left">
    <table width="100%" cellpadding="3px">
        <tr>
            <td width="150px">- Nama</td><td><?php echo $row['nama'];?></td>
        </tr>
        <tr>
            <td>- Tgl. Lahir</td><td><?php echo datefmysql($row['tgl_lahir']);?></td>
        </tr>
        <tr>
            <td>- Jenis Kelamin</td><td><?php echo $row['jenis_kelamin'];?></td>
        </tr>
        <tr>
            <td>- Orang Tua</td><td><?php echo $row['ortu'];?></td>
        </tr>
        <tr>
            <td>- Jumlah Saudara</td><td><?php echo ($row['jumlah_saudara']!=0)?$row['jumlah_saudara']:"-";?></td>
        </tr>
        <tr>
            <td>- Alamat</td><td><?php echo $row['alamat'];?></td>
        </tr>
        <tr>
            <td>- No. Telepon</td><td><?php echo ($row['no_telp']!="")?$row['no_telp']:"-"?></td>
        </tr>
        <tr>
            <td>- Sekolah</td><td><?php echo $row['sekolah'];?></td>
        </tr>
        <tr>
            <td>- Tingkat Pendidikan</td><td><?php echo $row['tingkat_pendidikan'];?></td>
        </tr>
        <tr>
            <td>- Kelas</td><td><?php echo $row['kelas'];?></td>
        </tr>
        <tr>
            <td>- Tahun Ajaran</td><td><?php echo $row['tahun_ajaran']." ".$row['semester'];?></td>
        </tr>
    </table>
    </div>
    <div style="width: 300px;float: left">
        Foto Calon Adik Asuh 
        <br /><br />
        <?php
            if($row['gambar'] == ''){
        ?>
          <img src="<?php echo base_url()."system/image/user_icon.png"?>" />
        <?php
            }else{
        ?> 
        <div id="photos">
          <img src="<?php echo base_url()."system/image/foto_calon_adik_asuh/thumbs/".$row['gambar']?>" rel="#mies1" title="klik untuk zoom"/>
        </div>
        <div class="simple_overlay" id="mies1"><div class="close"></div>
	   <img src="<?php echo base_url()."system/image/foto_calon_adik_asuh/".$row['gambar']?>" />
        </div>  
        <?php
           }
        ?>  
    </div>
</fieldset>
<p>Rekap Data Dinamis Calon Adik Asuh</p>
<div class="data-input">
    <fieldset class="add-form">
        <legend>Form Tambah Data Dinamis Calon Adik Asuh</legend>
        <?php
          echo form_open_multipart($subLink, '');
        ?>
          <label>Alamat</label><?php echo form_input("alamat","","id='alamat'");?>
          <label>No. Telepon</label><?php echo form_input("noTelp","","id='noTelp'");?>
          <label>Jumlah Saudara</label><?php echo form_input("jumSaudara","","id='jumSaudara'");?>
          <label>Sekolah</label><?php echo form_input('sekolah', '','id=sekolah');?>
          <input type="hidden" name="idSekolah" id="idSekolah" />
          <label>Kelas</label>
            <select name="kelas" id="kelas">
                <option value="">Pilih kelas</option>
            </select>
          <label>Tahun Ajaran</label>
          <span style="font-size: 12px;padding-top: 5px;">
              <?php
                echo $row['tahun_ajaran']." ".$row['semester'];
              ?>
          </span>
          <fieldset class="field-group">
               <label>Foto</label><?php echo form_upload('userfile');?>
          </fieldset>
          <fieldset class="input-process">
              <?php
                  echo form_hidden('idCalonAdikAsuh', $row['id']);
                  echo form_hidden('id_tahun_ajaran', $row['id_tahun_ajaran']);
                  echo form_submit("add", "Simpan", "class='button' style='margin-right:2px'");
                  echo form_button('Batal', 'Batal', 'class=button onClick='."javascript:location.href='".base_url()."index.php/calon_adik_asuh/detail_calon_adik_asuh/".$row['id']."'");
              ?>
          </fieldset>
        <?php
          echo form_close();
        ?>
    </fieldset>
</div>
<div class="data-list">
    <div class="floleft" style="margin: 8px 0">
       <?php
         echo addButton('#', 'tambah');
       ?>
    </div>
    <table class="tabel">
        <tr>
            <th>No</th>
            <th>Tanggal</th>
            <th>Alamat</th>
            <th>No. Telepon</th>
            <th>Jumlah Saudara</th>
            <th>Sekolah</th>
            <th>Kelas</th>
            <th>Tingkat Pendidikan</th>
            <th>Tahun Ajaran</th>
            <th>Status</th>
        </tr>
        <?php
            $no = 1;
            foreach ($dinamisCalonAdikAsuh as $row){
        ?>
          <tr class="<?php echo ($no%2)?"even":"odd";?>">
              <td style="width: 3%;text-align: center"><?php echo $no++;?></td>
              <td style="width: 8%;text-align: center"><?php echo datefmysql($row['tanggal']);?></td>
              <td><?php echo $row['alamat'];?></td>
              <td style="width: 8%;"><?php echo $row['no_telp'];?></td>
              <td style="width: 8%;"><?php echo $row['jumlah_saudara'];?></td>
              <td style="width: 20%;"><?php echo $row['sekolah'];?></td>
              <td style="width: 8%;"><?php echo $row['kelas'];?></td>
              <td style="width: 8%;"><?php echo $row['tingkat_pendidikan'];?></td>
              <td style="width: 10%;"><?php echo $row['tahun_ajaran']." ".$row['semester'];?></td>
              <td style="width: 8%;">
                  <?php
                    if($row['status'] == '1'){
                        echo "Aktif";
                    }else echo "Non-aktif";
                  ?>
              </td>
          </tr>
        <?php
            }
        ?>
    </table>
</div>
